package com.yunshipei.ui.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.yunshipei.common.Globals;
import com.yunshipei.enterplorer.R;

public class HomeIntroduceDialog extends Dialog {

    public HomeIntroduceDialog(Context context) {
        this(context, R.style.dialog_home_intrudoce);
    }

    public HomeIntroduceDialog(Context context, int themeResId) {
        super(context, themeResId);
        init(context);
    }

    protected HomeIntroduceDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init(context);
    }

    @SuppressLint("InflateParams")
    private void init(final Context context) {
        setCancelable(false);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        View content = LayoutInflater.from(context).inflate(R.layout.dialog_home_introduce, null);
        content.findViewById(R.id.hide_introduce_view).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                SharedPreferences preferences = context.getSharedPreferences(Globals.NO_CLEAR_SHP, Context.MODE_PRIVATE);
                preferences.edit().putBoolean(Globals.SHOULD_SHOW_INTRODUCE_VIEW, false).apply();
            }
        });
        setContentView(content);
        Window window = this.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(params);
    }
}
